﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using control.Biz;

namespace TrangSucShop.usercontrol
{
    public partial class Login : System.Web.UI.UserControl
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (Session["KhachHang"] != null)
            {
                lbThongBao.Text = "";
                MultiView1.ActiveViewIndex = 1;
                BizKhachHang kh = (BizKhachHang)Session["KhachHang"];
                lbTenKH.Text = kh.TenKhachHang;
            }
            else
            {
                MultiView1.ActiveViewIndex = 0;
            }
        }

        protected void Button1_Click(object sender, EventArgs e)
        {
            string username = txtUsername.Text;
            string password = txtPassword.Text;
            BizKhachHang kh = new BizKhachHang()
            {
                Username = username,
                Password = password
            };
            bool resuilt= kh.DangNhap();
            if (resuilt == true)
            {
                lbThongBao.Text = "";
                MultiView1.ActiveViewIndex = 1;
                Session["KhachHang"] = kh;
                lbTenKH.Text = kh.TenKhachHang;
                string url = Request.Url.ToString();
                Response.Redirect(url);
            }
            else
            {
                lbThongBao.Text = "Đăng Nhập Thất  Bại !!! ";
            }
        }

        protected void Button2_Click(object sender, EventArgs e)
        {
            Session["KhachHang"] = null;
            Response.Redirect("Default.aspx");
        }
    }
}